<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据字典管理</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../../res/js/jquery-3.1.1.min.js"></script>
    <script src="../../res/layui/layui.js"></script>
    <style type="text/css">
        body {
            margin: 0 auto;
            width: 100%;
            height: 100%;
        }
        .demoTable {
            width: 99%;
            height: 50px;
            margin: 0px auto;
            line-height: 50px;
        }

        #demo{
            width: 800px;

        }
    </style>
</head>
<body>
<div class="demoTable">

    <div class="layui-inline">
        <input class="layui-input" placeholder="输入字典名称" name="dname" id="dname"
               autocomplete="off" size="20">
    </div>
    <div class="layui-inline">
        <input class="layui-input" placeholder="输入字典类型" name="dtype" id="dtype"
               autocomplete="off" size="20">
    </div>
    <div class="layui-inline">
        <input class="layui-input" placeholder="输入字典编码" name="dcode" id="dcode"
               autocomplete="off" size="20">
    </div>

    <button class="layui-btn" data-type="reload" id="selectName">搜索</button>
    <button class="layui-btn " id="add" lay-event="addBtn">新增</button>
</div>
<table class="layui-hide" lay-filter="test" id="test"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit" style="width:60px;height:30px;line-height:30px">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" style="width:60px;height:30px;line-height:30px">删除</a>
</script>
<script>
    var table2 = null ;
    layui.use('table', function () {
        var table = layui.table, form = layui.form;

        table2 = table.render({
            elem: '#test'
            , url: '../../dicAction/selectAll'
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'dcode', width: 110, title: '字典编码', sort: true}
                , {field: 'dname', width: 110, title: '字典名称', sort: true}
                , {field: 'dtype', width: 110, title: '字典类型', sort: true}
                , {fixed: 'right', title: '操作', align: 'center', toolbar: '#barDemo', width: 200}
            ]]
            ,id: 'testReload'
            , page: true
        });
        $(function() {

            $("#add").on("click",function(){
                layer.open({
                    type: 2//样式
                    , skin: 'layui-layer-molv'//样式
                    , area: ['60%', '60%']
                    , title: "新增数据"//标题
                    , id: 'mesFrom' //防止重复弹出
                    , content: "DicAddAndUpdate.html"
                    , shade: [0.8, '#393D49'] //显示遮罩
                    , shadeClose: true//点击也能遮罩层关闭
                    , anim: 1//弹出动画
                });
            })
            //搜索
            $("#selectName").on("click",function(){
                table2.reload({
                    where : {
                        dname:$("#dname").val(),
                        dtype:$("#dtype").val(),
                        dcode:$("#dcode").val(),
                    },
                    page : {
                        curr : 1
                    }
                });
            })
        });
        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){

                    obj.del();

                    var url="../../dicAction/updateId";
                    var datas={id:data.did};
                    $.post(url,datas,function(obj){
                        if(obj==1){
                            layer.msg('删除成功');
                            table.reload('testReload');
                        }else{
                            layer.msg('删除失败');
                        }
                    },"json");
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type: 2//样式
                    , skin: 'layui-layer-molv'//样式
                    , area: ['60%', '60%']
                    , title: "修改数据"//标题
                    , id: 'mesFrom' //防止重复弹出
                    , content: "DicAddAndUpdate.html?id=" + data.did
                    , shade: [0.8, '#393D49'] //显示遮罩
                    , shadeClose: true//点击也能遮罩层关闭
                    , anim: 1//弹出动画
                });
            }
        });

    });

</script>



</body>
</html>